package org.walkerljl.practice;

import org.walkerljl.commons.io.FileUtils;
import org.walkerljl.commons.util.CollectionUtils;
import org.walkerljl.commons.util.ListUtils;

import java.io.*;
import java.util.List;

/**
 * TextReader
 *
 * @author lijunlin
 */
public class TextReader {

    public static void main(String[] args) throws IOException {
        File file = new File("C:/Users/俊林/Desktop/剔除商品SPU第三批 - 英语.txt");
        if (file.isFile() && file.exists()) {
            InputStreamReader ins = new InputStreamReader(new FileInputStream(file), "UTF-8");
            BufferedReader bufferedReader = new BufferedReader(ins);
            String lineTxt = null;
            List<String> items = ListUtils.newArrayList();
            while ((lineTxt = bufferedReader.readLine()) != null) {
                items.add(lineTxt);
            }

            System.out.println(CollectionUtils.wrap(items, ","));
            //writeFile("C:/Users/俊林/Desktop/", "zhangshuai-script.sql", sql.toString());
        }
    }

    public static void writeFile(String path, String fileName, String content) {
        BufferedWriter writer = null;
        try {
            FileUtils.mkdirs(path);
            writer = new BufferedWriter(new FileWriter(path + "/" + fileName));
            writer.write(content);
        } catch (Exception e) {
            //LOG.error("文件内容输出到指定文件出错,path={}", (path+"/"+fileName));
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (Exception e2) {
                    //LOG.error("关闭输出对象出错");
                }
            }
        }
    }
}